package org.jeecg.modules.emissionCarbon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.emissionCarbon.entity.EmissionCarbon;
import org.jeecg.modules.emissionCarbon.mapper.EmissionCarbonMapper;
import org.jeecg.modules.emissionCarbon.service.IEmissionCarbonService;
import org.springframework.stereotype.Service;

/**
 * @Description: 碳排放方案
 * @Author: jeecg-boot
 * @Date:   2023-06-20
 * @Version: V1.0
 */
@Service
public class EmissionCarbonServiceImpl extends ServiceImpl<EmissionCarbonMapper, EmissionCarbon> implements IEmissionCarbonService {

    @Override
    public void updateStatus(EmissionCarbon emissionCarbon){
        if ("默认方案".equals(emissionCarbon.getStatus())){
            EmissionCarbon carbon = new EmissionCarbon();
            carbon.setStatus("备用方案");
            baseMapper.update(carbon,null);
        }
    }

    @Override
    public EmissionCarbon getCoefficient() {
        LambdaQueryWrapper<EmissionCarbon> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.eq(EmissionCarbon::getStatus, "默认方案");
        return baseMapper.selectOne(queryWrapper);
    }
}
